package cn.com.common.job.task;


import java.util.List;

import org.quartz.DisallowConcurrentExecution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import cn.com.common.constants.Constants;
import cn.com.gas.entity.GasStationinfoEntity;
import cn.com.gas.service.GasStationinfoService;
import cn.com.system.entity.SysParameterEntity;
import cn.com.system.service.SysParameterService;
import cn.com.thirdparty.mapper.ProvinceGasStationinfoMapper;
import cn.com.util.TsBqUtils;

/**
 * 定时任务 推送到省局数据库
 *
 * @author wenbin
 * @version V1.0
 * @date 2020年3月18日
 */
@Component("gasPushProvinceStationInfoProcessTask")
@DisallowConcurrentExecution
public class GasPushProvinceStationInfoProcessTask {
	
	@Value("${gasstation.timedTask.gasPushProvinceStationInfoProcessTask}")
	private String gasPushProvinceStationInfoProcessTask;
	private Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private GasStationinfoService gasStationinfoService;
	@Autowired
	private ProvinceGasStationinfoMapper provinceGasStationinfoMapper;
	@Autowired
	private SysParameterService sysParameterService;
	
	public void run(String params) throws Exception {
		logger.debug("gasPushProvinceStationInfoProcessTask定时任务正在执行，参数为：{}", params);
		logger.debug("application参数为gasPushProvinceStationInfoProcessTask：{}", gasPushProvinceStationInfoProcessTask);
		if (gasPushProvinceStationInfoProcessTask.equals(Constants.JOB_STOP)) {
			logger.debug("application配置文件控制不执行gasStationInfoProcessTask定时任务");
			throw new Exception("application配置文件控制不执行gasStationInfoProcessTask定时任务");
		}
		SysParameterEntity parameterEntity106 = sysParameterService.getById("parameter106");

		if (TsBqUtils.isNotNull(parameterEntity106)) {
			String parameter106 = parameterEntity106.getParameter();
			if("Y".equals(parameter106)){
				List<GasStationinfoEntity> list = gasStationinfoService.list();
				// 删除全部油站
				provinceGasStationinfoMapper.realRemoveAll();
				// 重新插入油站
				for (GasStationinfoEntity gasStationinfoEntity : list) {
					provinceGasStationinfoMapper.insert(gasStationinfoEntity);
				}
			}
		}
		
		
	}
}
